# -*- coding: utf-8 -*-
from selenium import webdriver
from selenium.common.exceptions import TimeoutException
from selenium.webdriver.support.ui import WebDriverWait # available since 2.4.0
from selenium.webdriver.support import expected_conditions as EC # available since 2.26.0
from selenium.webdriver.common.action_chains import ActionChains
import unittest
import random
import time
from cookies import lasthopes, randomword
import re
import string
import sys
from selenium.webdriver.common.keys import Keys
from PIL import Image
from os import remove, listdir, sep
from os.path import basename, isfile
import tempfile
from warnings import warn
from basecart import BaseCart

class cart_remove_restore(BaseCart):
    def test_remove_restore(self):
        driver = self.driver
        for i in range(0,2):
            self.get_cat()
            self.get_item()
            self.buy_item()        
        self.go_cart()
        remove_btn = WebDriverWait(driver, timeout=10).until(lambda dr: [a for a in
                                        dr.find_elements_by_css_selector("input.b-sbutton-input") if\
                                                       re.match("remove.*", a.get_attribute("name"))])[0]
        count_bfr = self.cart_items_ontop()
        remove_btn.click()
        #Check for count decreased
        WebDriverWait(self.driver, timeout=10).until(lambda dr: self.cart_items_ontop()<count_bfr)
        restore = WebDriverWait(driver, timeout=10).until(lambda dr: dr\
                                 .find_element_by_css_selector("span.g-pseudo.g-link.js-cart-order-item-repair"))
        cart_btn = WebDriverWait(driver, timeout=10).until(lambda dr: dr\
                                 .find_element_by_css_selector("div.b-header-top-cell-h"))
        count_bfr = self.cart_items_ontop()
        restore.click()
        #Check for count increased
        WebDriverWait(self.driver, timeout=10).until(lambda dr: self.cart_items_ontop()>count_bfr)
